<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of rbfbkp</title>
  <meta name="keywords" content="rbfbkp">
  <meta name="description" content="RBFBKP	Backpropagate gradient of error function for RBF network.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; rbfbkp.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>rbfbkp
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>RBFBKP	Backpropagate gradient of error function for RBF network.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function g = rbfbkp(net, x, z, n2, deltas) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">RBFBKP    Backpropagate gradient of error function for RBF network.

    Description
    G = RBFBKP(NET, X, Z, N2, DELTAS) takes a network data structure NET
    together with a matrix X of input vectors, a matrix  Z of hidden unit
    activations, a matrix N2 of the squared distances between centres and
    inputs, and a matrix DELTAS of the  gradient of the error function
    with respect to the values of the output units (i.e. the summed
    inputs to the output units, before the activation function is
    applied). The return value is the gradient G of the error function
    with respect to the network weights. Each row of X corresponds to one
    input vector.

    This function is provided so that the common backpropagation
    algorithm can be used by RBF network models to compute gradients for
    the output values (in RBFDERIV) as well as standard error functions.

    See also
    <a href="rbf.html" class="code" title="function net = rbf(nin, nhidden, nout, rbfunc, outfunc, prior, beta)">RBF</a>, <a href="rbfgrad.html" class="code" title="function [g, gdata, gprior] = rbfgrad(net, x, t)">RBFGRAD</a>, <a href="rbfderiv.html" class="code" title="function g = rbfderiv(net, x)">RBFDERIV</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="rbfderiv.html" class="code" title="function g = rbfderiv(net, x)">rbfderiv</a>	RBFDERIV Evaluate derivatives of RBF network outputs with respect to weights.</li><li><a href="rbfgrad.html" class="code" title="function [g, gdata, gprior] = rbfgrad(net, x, t)">rbfgrad</a>	RBFGRAD Evaluate gradient of error function for RBF network.</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function g = rbfbkp(net, x, z, n2, deltas)</a>
0002 <span class="comment">%RBFBKP    Backpropagate gradient of error function for RBF network.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%    G = RBFBKP(NET, X, Z, N2, DELTAS) takes a network data structure NET</span>
0006 <span class="comment">%    together with a matrix X of input vectors, a matrix  Z of hidden unit</span>
0007 <span class="comment">%    activations, a matrix N2 of the squared distances between centres and</span>
0008 <span class="comment">%    inputs, and a matrix DELTAS of the  gradient of the error function</span>
0009 <span class="comment">%    with respect to the values of the output units (i.e. the summed</span>
0010 <span class="comment">%    inputs to the output units, before the activation function is</span>
0011 <span class="comment">%    applied). The return value is the gradient G of the error function</span>
0012 <span class="comment">%    with respect to the network weights. Each row of X corresponds to one</span>
0013 <span class="comment">%    input vector.</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%    This function is provided so that the common backpropagation</span>
0016 <span class="comment">%    algorithm can be used by RBF network models to compute gradients for</span>
0017 <span class="comment">%    the output values (in RBFDERIV) as well as standard error functions.</span>
0018 <span class="comment">%</span>
0019 <span class="comment">%    See also</span>
0020 <span class="comment">%    RBF, RBFGRAD, RBFDERIV</span>
0021 <span class="comment">%</span>
0022 
0023 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0024 
0025 <span class="comment">% Evaluate second-layer gradients.</span>
0026 gw2 = z'*deltas;
0027 gb2 = sum(deltas);
0028 
0029 <span class="comment">% Evaluate hidden unit gradients</span>
0030 delhid = deltas*net.w2';
0031 
0032 gc = zeros(net.nhidden, net.nin);
0033 ndata = size(x, 1);
0034 t1 = ones(ndata, 1);
0035 t2 = ones(1, net.nin);
0036 <span class="comment">% Switch on activation function type</span>
0037 <span class="keyword">switch</span> net.actfn
0038       
0039 <span class="keyword">case</span> <span class="string">'gaussian'</span> <span class="comment">% Gaussian</span>
0040    delhid = (delhid.*z);
0041    <span class="comment">% A loop seems essential, so do it with the shortest index vector</span>
0042    <span class="keyword">if</span> (net.nin &lt; net.nhidden)
0043       <span class="keyword">for</span> i = 1:net.nin
0044          gc(:,i) = (sum(((x(:,i)*ones(1, net.nhidden)) - <span class="keyword">...</span>
0045             (ones(ndata, 1)*(net.c(:,i)'))).*delhid, 1)./net.wi)';
0046       <span class="keyword">end</span>
0047    <span class="keyword">else</span>
0048       <span class="keyword">for</span> i = 1:net.nhidden
0049          gc(i,:) = sum((x - (t1*(net.c(i,:)))./net.wi(i)).*(delhid(:,i)*t2), 1);
0050       <span class="keyword">end</span>
0051    <span class="keyword">end</span>
0052    gwi = sum((n2.*delhid)./(2.*(ones(ndata, 1)*(net.wi.^2))), 1);
0053    
0054 <span class="keyword">case</span> <span class="string">'tps'</span>    <span class="comment">% Thin plate spline activation function</span>
0055    delhid = delhid.*(1+log(n2+(n2==0)));
0056    <span class="keyword">for</span> i = 1:net.nhidden
0057       gc(i,:) = sum(2.*((t1*(net.c(i,:)) - x)).*(delhid(:,i)*t2), 1);
0058    <span class="keyword">end</span>
0059    <span class="comment">% widths are not adjustable in this model</span>
0060    gwi = [];
0061 <span class="keyword">case</span> <span class="string">'r4logr'</span> <span class="comment">% r^4 log r activation function</span>
0062    delhid = delhid.*(n2.*(1+2.*log(n2+(n2==0))));
0063    <span class="keyword">for</span> i = 1:net.nhidden
0064       gc(i,:) = sum(2.*((t1*(net.c(i,:)) - x)).*(delhid(:,i)*t2), 1);
0065    <span class="keyword">end</span>
0066    <span class="comment">% widths are not adjustable in this model</span>
0067    gwi = [];
0068 <span class="keyword">otherwise</span>
0069    error(<span class="string">'Unknown activation function in rbfgrad'</span>)
0070 <span class="keyword">end</span>
0071    
0072 g = [gc(:)', gwi, gw2(:)', gb2];</pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>